load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("//build:STRINGER.bzl", "stringer")

go_library(
    name = "scop",
    srcs = [
        "backfill.go",
        "deferred_mutation.go",
        "immediate_mutation.go",
        "metadata.go",
        "ops.go",
        "phase.go",
        "validation.go",
        ":gen-backfill",  # keep
        ":gen-deferred-mutation",  # keep
        ":gen-immediate-mutation",  # keep
        ":gen-phase-stringer",  # keep
        ":gen-type-stringer",  # keep
        ":gen-validation",  # keep
    ],
    importpath = "github.com/cockroachdb/cockroach/pkg/sql/schemachanger/scop",
    visibility = ["//visibility:public"],
    deps = [
        "//pkg/config/zonepb",
        "//pkg/jobs/jobspb",
        "//pkg/sql/catalog/catenumpb",
        "//pkg/sql/catalog/catpb",
        "//pkg/sql/catalog/descpb",
        "//pkg/sql/schemachanger/scpb",
        "//pkg/sql/sem/catid",
        "//pkg/sql/sem/semenumpb",
    ],
)

genrule(
    name = "gen-immediate-mutation",
    srcs = ["immediate_mutation.go"],
    outs = ["immediate_mutation_visitor_generated.go"],
    cmd = """
        $(location //pkg/sql/schemachanger/scop/generate-visitors) scop ImmediateMutation $(location immediate_mutation.go) $(location immediate_mutation_visitor_generated.go)
       """,
    tools = [
        "//pkg/sql/schemachanger/scop/generate-visitors",
    ],
    visibility = [
        ":__pkg__",
        "//pkg/gen:__pkg__",
    ],
)

genrule(
    name = "gen-deferred-mutation",
    srcs = ["deferred_mutation.go"],
    outs = ["deferred_mutation_visitor_generated.go"],
    cmd = """
        $(location //pkg/sql/schemachanger/scop/generate-visitors) scop DeferredMutation $(location deferred_mutation.go) $(location deferred_mutation_visitor_generated.go)
       """,
    tools = [
        "//pkg/sql/schemachanger/scop/generate-visitors",
    ],
    visibility = [
        ":__pkg__",
        "//pkg/gen:__pkg__",
    ],
)

genrule(
    name = "gen-backfill",
    srcs = ["backfill.go"],
    outs = ["backfill_visitor_generated.go"],
    cmd = """
        $(location //pkg/sql/schemachanger/scop/generate-visitors) scop Backfill $(location backfill.go) $(location backfill_visitor_generated.go)
       """,
    tools = [
        "//pkg/sql/schemachanger/scop/generate-visitors",
    ],
    visibility = [
        ":__pkg__",
        "//pkg/gen:__pkg__",
    ],
)

genrule(
    name = "gen-validation",
    srcs = ["validation.go"],
    outs = ["validation_visitor_generated.go"],
    cmd = """
        $(location //pkg/sql/schemachanger/scop/generate-visitors) scop Validation $(location validation.go) $(location validation_visitor_generated.go)
       """,
    tools = [
        "//pkg/sql/schemachanger/scop/generate-visitors",
    ],
    visibility = [
        ":__pkg__",
        "//pkg/gen:__pkg__",
    ],
)

stringer(
    name = "gen-type-stringer",
    src = "ops.go",
    typ = "Type",
)

stringer(
    name = "gen-phase-stringer",
    src = "phase.go",
    typ = "Phase",
)
